<template>
<!--  修改异常信息-->
  <el-dialog
      v-model="dialogVisible"
      title="Tips"
      width="500"
      :before-close="handleClose"
  >

    <el-form
        ref="ruleFormRef"
        style="max-width: 600px"
        :model="ruleForm"
        status-icon
        :rules="rules"
        label-width="auto"
        class="demo-ruleForm"
    >
      <el-form-item label="处理异常信息" prop="pass">
        <el-input v-model="ruleForm.exceptionMessage"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm()">
          处理
        </el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
<!--查询所有-->
    <el-table
        ref="multipleTableRef"
        :data="tableData"
        style="width: 100%"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column property="id" label="ID" width="80" />
      <el-table-column property="exceptionalType" label="异常类型"/>
      <el-table-column property="deviceNo" label="设备编号" />
      <el-table-column property="exceptionMessage" label="异常信息"/>
      <el-table-column property="status" label="异常信息">
        <template #default="scope">
         <span>
           <template v-if="scope.row.status==1">未处理</template>
           <template v-else-if="scope.row.status==0">已处理</template>
         </span>
        </template>
      </el-table-column>
      <el-table-column label="Operations">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.row)">
            处理
          </el-button>
          <el-button
              size="small"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
          >
            Delete
          </el-button>
        </template>
      </el-table-column>
    </el-table>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { Search, Refresh } from '@element-plus/icons-vue'
import {requestException} from "@/utils/request.js"
import { ElMessage, ElMessageBox } from 'element-plus'

// 数据相关
const tableData = ref([])
const loading = ref(false)
const total = ref(0)

// 获取表格数据
// 查询所有

function selectAll(){
  requestException({
    url:'/admin/exceptional/selectAllExeception',
    method:'get'
  }).then(res=>{
    console.log(res)
    tableData.value=res.data.data

  })
}
selectAll()

const dialogVisible = ref(false)
const ruleForm = ref({
  exceptionMessage:"",
})
function handleEdit(row){
  dialogVisible.value=true
  ruleForm.value=row
}
function submitForm(){
  requestException({
    url:"/admin/exceptional/update",
    method:"post",
    data:ruleForm.value,
  }).then(res=>{
    if(res.status==200){
      ElMessage({
        type: 'success',
        message: '修改成功'
      })
      selectAll()
      dialogVisible.value=false
    }
  })
}
</script>

